<?php
 
/*
 * Following code will update a product information
 * A product is identified by product id (pid)
 */
 
// array for JSON response
$response = array();
 
// check for required fields
if (isset($_POST['place_id'])
	 && isset($_POST['place_name']) 
	 && isset($_POST['address'])  
	 && isset($_POST['district_id']) 
	 && isset($_POST['longitude'])
	 && isset($_POST['latitude']) 
	 && isset($_POST['phone_number']) 
	 && isset($_POST['fax_number']) 
	 && isset($_POST['email'])
	 && isset($_POST['website'])
	 && isset($_POST['open_time'])	 
	 && isset($_POST['close_time'])  
	 && isset($_POST['lowest_price'])
	 && isset($_POST['hightest_price']) 
	 && isset($_POST['description']) 
	 && isset($_POST['url_avatar'])
	 && isset($_POST['name_avatar'])
	 && isset($_POST['public']))
	 && isset($_POST['delete'])) {
	$place_id = $_POST['place_id'];
    $place_name = $_POST['place_name'];
	$address = $_POST['address'];
	$longitude = $_POST['longitude'];
	$latitude = $_POST['latitude'];
	$district_id = $_POST['district_id'];		 
	$phone_number = $_POST['phone_number'];
	$fax_number = $_POST['fax_number'];
	$email = $_POST['email'];
	$website = $_POST['website'];
	$open_time = $_POST['open_time'];		 
	$close_time = $_POST['close_time'];
	$lowest_price = $_POST['lowest_price'];
	$hightest_price = $_POST['hightest_price'];
	$url_avatar = $_POST['url_avatar'];
	$name_avatar = $_POST['name_avatar'];	
	$description = $_POST['description'];
	$delete = $_POST['delete'];
	$public = $_POST['public'];
 
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
 
    // connecting to db
    $db = new DB_CONNECT();
 
    // mysql update row with matched pid
    $result = mysql_query("UPDATE Place SET place_name='$place_name'
										,address='$address'
										,longitude='$longitude'
										,latitude='$latitude'
										,district_id='$district_id'
										,phone_number='$phone_number'
										,fax_number='$fax_number'
										,email='$email'
										,website='$website'
										,open_time='$open_time'
										,close_time='$close_time'
										,lowest_price='$lowest_price'
										,hightest_price='$hightest_price'
										,url_avatar='$url_avatar'
										,name_avatar='$name_avatar'
										,description='$description'
										,delete='$delete'
										,public='$public'
										WHERE place_id = $place_id");
									
    // check if row inserted or not
    if ($result) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Successfully updated.";
 
        // echoing JSON response
        echo json_encode($response);
    } else {
 
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}
?>